// This File Creates Plots for Market Cap and the Ratio of Margin Debt
// to Aggregate Market Cap


/* Margin Debt */
use ../src/daily_margin.dta, clear
collapse (sum) margin_hold (sum) float_cap	, by(date)
gen margin_cap=margin_hold/float_cap
replace float_cap=float_cap/1000000000000

twoway  (line float_cap	 date, lpattern(solid) lcolor(black) yaxis(1) lwidth(medthick)) ///
		 (line margin_cap date, lcolor(eltblue) lpattern(solid) yaxis(2) lwidth(medthick) ), /// 
		graphregion(color(white) ) ///
		ytitle("Margin Debt/Market Cap", axis(2) ) ///
		xtitle("")  ///
		ylabel(0(20)60, axis(1) nogrid) ///
		ylabel(0 "0%" 0.01 "1%"  0.02 "2%" 0.03 "3%" .04 "4%"  .05 "5%", nogrid axis(2)) ///
		xlabel(18444 "2010" 18809 "2011" 19175 "2012" 19540 "2013" 19905 "2014" 20270 "2015") ///
		ytitle("Aggregate Market Cap. in Trillions") ///
		legend( on r(1) pos(6) region(lcolor(white)) size(small) label(1 Market Cap) label(2 Margin Debt/Market Cap) ) 
 
 
 graph export ../gph/aggregate_margin_cap.pdf, replace font(palatino)
